#pragma once

#include "utilities.h"


#define CAR_POS_Y	0.345f						// Car position under the road. Calculated from the car model


class CCar
{
public:
	CCar(IrrlichtDevice* device, f32 maxSpeed);
	~CCar();

	void			update(int accelDir, int turnDir);
	bool			checkCollision(ISceneNode* node);
	int				genTurn(vector3df& point);

	ISceneNode*		getNode();
	vector3df		getPosition();
	f32				getAngle();
	f32				getSpeed();
	f32				getMaxSpeed();
	
	void			setMaxSpeed(f32 speed);
	void			setPosition(vector3df& position);

	enum {ACCEL_NO = 0, ACCEL_FRWD, ACCEL_BCKWD};
	enum {TURN_NO = 0, TURN_LEFT = 1, TURN_RIGHT = -1};
	
private:
	IVideoDriver*	driver;
	ISceneManager*	smgr;
	
	ISceneNode*		bodyNode;
	ISceneNode*		wheelNode[4];
	
	vector3df		bodySize;
	vector3df		lastPosition;
	
	f32				wheelRadius;
	vector3df		wheelPosition[4];
	
	f32				accel;

	f32				linearVelocity;
	f32				angularVelocity;
	
	f32				maxSpeed;
	
	f32				wheelsRotation;				// Wheels rotation around x-axis
	
	f32				wheelsTurn;					// Wheels turn around y-axis
	f32				wheelsMaxTurn;				// Wheels max turn angle
	f32				wheelsTurnSpeed;			// Wheels rotation speed (degrees per cycle)

	ISceneCollisionManager* collmgr;
	
	int	turnToPoint(vector3df& point, f32 rayLenght, f32 rayIndent);
	void updateWheels(void);
};
